home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdckbd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  24.6 KB  |  875 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. /*#define NEEDS_OS2       1*/
  20.  
  21. #if    defined (DOS)
  22. #include <conio.h>
  23. #endif
  24.  
  25. #define    CURSES_LIBRARY    1
  26. #include <curses.h>
  27.  
  28. #ifdef OS2
  29. #  if defined (CURSES__32BIT__) || defined(CSET2) || defined(TC)
  30. #     include <signal.h>
  31. #  else
  32. #     define INCL_DOSSIGNALS
  33. #     define INCL_NOCOMMON
  34. #     include <bsedos.h>
  35. #  endif
  36. #endif
  37.  
  38. #ifdef UNIX
  39. #include <signal.h>
  40. #endif
  41.  
  42. #ifdef PDCDEBUG
  43. char *rcsid_PDCkbd  = "$Id$";
  44. #endif
  45.  
  46. /*******************************************************************************
  47. *    Table for key code translation of function keys in keypad mode
  48. *    These values are for strict IBM keyboard compatibles only
  49. *******************************************************************************/
  50.  
  51.  
  52. #if    defined(DOS) || defined(OS2)
  53. static int kptab[] =
  54. {
  55.  /* Normal Function Keys     */
  56.  0x3b, KEY_F(1), 0x3c, KEY_F(2), 0x3d, KEY_F(3), 0x3e, KEY_F(4),
  57.  0x3f, KEY_F(5), 0x40, KEY_F(6), 0x41, KEY_F(7), 0x42, KEY_F(8),
  58.  0x43, KEY_F(9), 0x44, KEY_F(10),
  59.  
  60.  /* Normal Keypad         */
  61.  0x47, KEY_HOME, 0x48, KEY_UP,   0x49, KEY_PPAGE,
  62.  0x4b, KEY_LEFT, 0x4c, KEY_B2,   0x4d, KEY_RIGHT,
  63.  0x4f, KEY_END,  0x50, KEY_DOWN, 0x51, KEY_NPAGE,
  64.  0x52, KEY_IC,   0x53, KEY_DC,
  65.  
  66.  /* Shft-Function Keys     */
  67.  0x54, KEY_F(11), 0x55, KEY_F(12), 0x56, KEY_F(13), 0x57, KEY_F(14),
  68.  0x58, KEY_F(15), 0x59, KEY_F(16), 0x5a, KEY_F(17), 0x5b, KEY_F(18),
  69.  0x5c, KEY_F(19), 0x5d, KEY_F(20),
  70.  
  71.  /* Ctl-Function Keys     */
  72.  0x5e, KEY_F(21), 0x5f, KEY_F(22), 0x60, KEY_F(23), 0x61, KEY_F(24),
  73.  0x62, KEY_F(25), 0x63, KEY_F(26), 0x64, KEY_F(27), 0x65, KEY_F(28),
  74.  0x66, KEY_F(29), 0x67, KEY_F(30),
  75.  
  76.  /* Alt-Function Keys     */
  77.  0x68, KEY_F(31), 0x69, KEY_F(32), 0x6a, KEY_F(33), 0x6b, KEY_F(34),
  78.  0x6c, KEY_F(35), 0x6d, KEY_F(36), 0x6e, KEY_F(37), 0x6f, KEY_F(38),
  79.  0x70, KEY_F(39), 0x71, KEY_F(40),
  80.  
  81.  /* Control-Keypad         */
  82.  0x77, CTL_HOME, 0x84, CTL_PGUP,
  83.  0x73, CTL_LEFT, 0x74, CTL_RIGHT,
  84.  0x75, CTL_END, 0x76, CTL_PGDN,
  85.  
  86.  /* Alt-Numbers         */
  87.  0x78, ALT_1, 0x79, ALT_2, 0x7a, ALT_3, 0x7b, ALT_4,
  88.  0x7c, ALT_5, 0x7d, ALT_6, 0x7e, ALT_7, 0x7f, ALT_8,
  89.  0x80, ALT_9, 0x81, ALT_0,
  90.  
  91.  /* Extended codes         */
  92.  0x85, KEY_F(41), 0x86, KEY_F(42), 0x87, KEY_F(43), 0x88, KEY_F(44),
  93.  0x89, KEY_F(45), 0x8a, KEY_F(46), 0x8b, KEY_F(47), 0x8c, KEY_F(48),
  94.  0x03, 0, /* NULL */
  95.  0xff, PADSLASH,     0x0d, PADENTER,      0x0a, CTL_PADENTER,
  96.  0xa6, ALT_PADENTER, 0x53, SHF_PADSTOP,   0xfc, CTL_ENTER,
  97.  0xfa, PADSTAR,      0xfd, PADMINUS,      0xfb, PADPLUS,
  98.  0x93, CTL_PADSTOP,  0x8f, CTL_PADCENTER, 0x90, CTL_PADPLUS,
  99.  0x8e, CTL_PADMINUS, 0x95, CTL_PADSLASH,  0x96, CTL_PADSTAR,
  100.  0x4e, ALT_PADPLUS,  0x4a, ALT_PADMINUS,  0xa4, ALT_PADSLASH,
  101.  0x37, ALT_PADSTAR,  0x92, CTL_INS,       0xa2, ALT_INS,
  102.  0xa3, ALT_DEL,      0x8d, CTL_UP,        0x91, CTL_DOWN,
  103.  0x94, CTL_TAB,      0xa5, ALT_TAB,       0x82, ALT_MINUS,
  104.  0x83, ALT_EQUAL,    0x99, ALT_PGUP,      0xa1, ALT_PGDN,
  105.  0x9f, ALT_END,      0x98, ALT_UP,        0xa0, ALT_DOWN,
  106.  0x9d, ALT_RIGHT,    0x9b, ALT_LEFT,      0x1c, ALT_ENTER,
  107.  0x97, ALT_HOME,     0x01, ALT_ESC,       0x0e, ALT_BKSP,
  108.  0x29, ALT_BQUOTE,   0x1a, ALT_LBRACKET,  0x1b, ALT_RBRACKET,
  109.  0x27, ALT_SEMICOLON,0x28, ALT_FQUOTE,    0x33, ALT_COMMA,
  110.  0x34, ALT_STOP,     0x35, ALT_FSLASH,    0x2b, ALT_BSLASH,
  111.  
  112.  /* Alt-Alphabet         */
  113.  0x1e, ALT_A, 0x30, ALT_B, 0x2e, ALT_C, 0x20, ALT_D,
  114.  0x12, ALT_E, 0x21, ALT_F, 0x22, ALT_G, 0x23, ALT_H,
  115.  0x17, ALT_I, 0x24, ALT_J, 0x25, ALT_K, 0x26, ALT_L,
  116.  0x32, ALT_M, 0x31, ALT_N, 0x18, ALT_O, 0x19, ALT_P,
  117.  0x10, ALT_Q, 0x13, ALT_R, 0x1f, ALT_S, 0x14, ALT_T,
  118.  0x16, ALT_U, 0x2f, ALT_V, 0x11, ALT_W, 0x2d, ALT_X,
  119.  0x15, ALT_Y, 0x2c, ALT_Z,
  120.  0x0f, KEY_BACKTAB,
  121.  0x100, (-1)
  122. };
  123.  /* End of kptab[]         */
  124. #endif
  125.  
  126. #ifdef    FLEXOS
  127. int    kptab[] =
  128. {
  129.  /* Normal Function Keys     */
  130.  0x1001, KEY_F(1), 0x1002, KEY_F(2), 0x1003, KEY_F(3), 0x1004, KEY_F(4),
  131.  0x1005, KEY_F(5), 0x1006, KEY_F(6), 0x1007, KEY_F(7), 0x1008, KEY_F(8),
  132.  0x1009, KEY_F(9), 0x100A, KEY_F(10),
  133.  
  134.  /* Normal Keypad         */
  135.  0x2018, KEY_HOME, 0x2010, KEY_UP, 0x2014, KEY_PPAGE,
  136.  0x2012, KEY_LEFT, 0x2035, KEY_B2, 0x2013, KEY_RIGHT,
  137.  0x2008, KEY_LL, 0x2011, KEY_DOWN, 0x2015, KEY_NPAGE,
  138.  0x2009, KEY_IC, 0x200A, KEY_DC,
  139.  
  140.  /* Shft-Function Keys     */
  141.  0x1401, KEY_F(11), 0x1402, KEY_F(12), 0x1403, KEY_F(13), 0x1404, KEY_F(14),
  142.  0x1405, KEY_F(15), 0x1406, KEY_F(16), 0x1407, KEY_F(17), 0x1408, KEY_F(18),
  143.  0x1409, KEY_F(19), 0x140A, KEY_F(20),
  144.  
  145.  /* Ctl-Function Keys     */
  146.  0x1101, KEY_F(21), 0x1102, KEY_F(22), 0x1103, KEY_F(23), 0x1104, KEY_F(24),
  147.  0x1105, KEY_F(25), 0x1106, KEY_F(26), 0x1107, KEY_F(27), 0x1108, KEY_F(28),
  148.  0x1109, KEY_F(29), 0x110A, KEY_F(30),
  149.  
  150.  /* Alt-Function Keys     */
  151.  0x1201, KEY_F(31), 0x1202, KEY_F(32), 0x1203, KEY_F(33), 0x1204, KEY_F(34),
  152.  0x1205, KEY_F(35), 0x1206, KEY_F(36), 0x1207, KEY_F(37), 0x1208, KEY_F(38),
  153.  0x1209, KEY_F(39), 0x120A, KEY_F(40),
  154.  
  155.  /* Control-Keypad         */
  156.  0x2118, CTL_HOME, 0x2114, CTL_PGUP,
  157.  0x2112, CTL_LEFT, 0x2113, CTL_RIGHT,
  158.  0x2108, CTL_END, 0x2115, CTL_PGDN,
  159.  
  160.  /* Alt-Numbers         */
  161.  0x2231, ALT_1, 0x2232, ALT_2, 0x2233, ALT_3, 0x2234, ALT_4,
  162.  0x2235, ALT_5, 0x2236, ALT_6, 0x2237, ALT_7, 0x2238, ALT_8,
  163.  0x2239, ALT_9, 0x2230, ALT_0,
  164.  
  165.  /* Alt-Alphabet         */
  166.  0x0200 | (unsigned) 'A', ALT_A, 0x0200 | (unsigned) 'B', ALT_B,
  167.  0x0200 | (unsigned) 'C', ALT_C, 0x0200 | (unsigned) 'D', ALT_D,
  168.  0x0200 | (unsigned) 'E', ALT_E, 0x0200 | (unsigned) 'F', ALT_F,
  169.  0x0200 | (unsigned) 'G', ALT_G, 0x0200 | (unsigned) 'H', ALT_H,
  170.  0x0200 | (unsigned) 'I', ALT_I, 0x0200 | (unsigned) 'J', ALT_J,
  171.  0x0200 | (unsigned) 'K', ALT_K, 0x0200 | (unsigned) 'L', ALT_L,
  172.  0x0200 | (unsigned) 'M', ALT_M, 0x0200 | (unsigned) 'N', ALT_N,
  173.  0x0200 | (unsigned) 'O', ALT_O, 0x0200 | (unsigned) 'P', ALT_P,
  174.  0x0200 | (unsigned) 'Q', ALT_Q, 0x0200 | (unsigned) 'R', ALT_R,
  175.  0x0200 | (unsigned) 'S', ALT_S, 0x0200 | (unsigned) 'T', ALT_T,
  176.  0x0200 | (unsigned) 'U', ALT_U, 0x0200 | (unsigned) 'V', ALT_V,
  177.  0x0200 | (unsigned) 'W', ALT_W, 0x0200 | (unsigned) 'X', ALT_X,
  178.  0x0200 | (unsigned) 'Y', ALT_Y, 0x0200 | (unsigned) 'Z', ALT_Z,
  179.  
  180.  0x0200 | (unsigned) 'a', ALT_A, 0x0200 | (unsigned) 'b', ALT_B,
  181.  0x0200 | (unsigned) 'c', ALT_C, 0x0200 | (unsigned) 'd', ALT_D,
  182.  0x0200 | (unsigned) 'e', ALT_E, 0x0200 | (unsigned) 'f', ALT_F,
  183.  0x0200 | (unsigned) 'g', ALT_G, 0x0200 | (unsigned) 'h', ALT_H,
  184.  0x0200 | (unsigned) 'i', ALT_I, 0x0200 | (unsigned) 'j', ALT_J,
  185.  0x0200 | (unsigned) 'k', ALT_K, 0x0200 | (unsigned) 'l', ALT_L,
  186.  0x0200 | (unsigned) 'm', ALT_M, 0x0200 | (unsigned) 'n', ALT_N,
  187.  0x0200 | (unsigned) 'o', ALT_O, 0x0200 | (unsigned) 'p', ALT_P,
  188.  0x0200 | (unsigned) 'q', ALT_Q, 0x0200 | (unsigned) 'r', ALT_R,
  189.  0x0200 | (unsigned) 's', ALT_S, 0x0200 | (unsigned) 't', ALT_T,
  190.  0x0200 | (unsigned) 'u', ALT_U, 0x0200 | (unsigned) 'v', ALT_V,
  191.  0x0200 | (unsigned) 'w', ALT_W, 0x0200 | (unsigned) 'x', ALT_X,
  192.  0x0200 | (unsigned) 'y', ALT_Y, 0x0200 | (unsigned) 'z', ALT_Z,
  193.  
  194.  0x0f, KEY_BACKTAB,
  195.  
  196.  /* End of kptab[]         */
  197.  0x100, -1
  198. };
  199. #endif
  200.  
  201. /*man-start*********************************************************************
  202.  
  203.   PDC_breakout()    - check for type-ahead
  204.  
  205.   X/Open Description:
  206.      The curses package does the "line-breakout optimisation" by
  207.      looking for type-ahead periodically while updating the screen.
  208.      If input is found, the current update will be postponed until
  209.      refresh() or doupdate() are called again.  This allows faster
  210.      response to commands typed in advance.  Normally, the input FILE
  211.      pointer passed to newterm(), or stdin in the case when initscr()
  212.      was called, will be used to do this type-ahead checking.  This routine
  213.      will do the actual check for PDcurses to see if input is pending.
  214.  
  215.   PDCurses Description:
  216.      This routine does what the PDcurses typeahead routine used to do.  But
  217.      to make that routine consistent with its System V counterpart, all it
  218.      does now is set whether or not typeahead checking is performed.
  219.  
  220.   X/Open Return Value:
  221.      The PDC_breakout() routine returns TRUE if keyboard input is pending
  222.      otherwise FALSE is returned.
  223.  
  224.   Portability:
  225.      PDCurses    bool PD_breakout( void );
  226.  
  227. **man-end**********************************************************************/
  228.  
  229. bool    PDC_breakout( void )
  230. {
  231. extern    int    c_pindex;            /* putter index */
  232. extern    int    c_gindex;            /* getter index */
  233. extern    int    c_ungind;            /* wungetch() push index */
  234. #ifdef    TC
  235. #  pragma argsused
  236. #endif
  237.  
  238.  
  239. #ifdef PDCDEBUG
  240.     if (trace_on) PDC_debug("PDC_breakout() - called\n");
  241. #endif
  242.  
  243.     if (c_ungind)
  244.         return (TRUE);            /* ungotten char */
  245.     if (c_pindex > c_gindex)
  246.         return (TRUE);            /* buffered char */
  247.     if (_cursvar.raw_inp)
  248.         return((bool)PDC_check_bios_key());/* raw mode test */
  249.  
  250.     return((bool)PDC_check_bios_key());    /* normal mode test */
  251. }
  252.  
  253. /*man-start*********************************************************************
  254.  
  255.   PDC_check_bios_key()    - Check BIOS key data area for input
  256.  
  257.   PDCurses Description:
  258.      This is a private PDCurses routine.
  259.  
  260.      This routine will check the BIOS for any indication that
  261.      keystrokes are pending.
  262.  
  263.   PDCurses Return Value:
  264.      Returns 1 if a keyboard character is available, 0 otherwise.
  265.  
  266.   PDCurses Errors:
  267.      No errors are defined for this function.
  268.  
  269.   Portability:
  270.      PDCurses    bool    PDC_check_bios_key( void );
  271.  
  272. **man-end**********************************************************************/
  273.  
  274. bool PDC_check_bios_key(void)
  275. {
  276. #ifdef    OS2
  277. # if !defined(MSC) && !defined(EMXVIDEO)
  278.     KBDKEYINFO keyInfo={0};
  279. # endif
  280. #endif
  281.  
  282. #ifdef PDCDEBUG
  283.     if (trace_on) PDC_debug("PDC_check_bios_key() - called\n");
  284. #endif
  285.  
  286. #ifdef    FLEXOS
  287.     retcode = s_get(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  288.     return( (retcode < 0L) ? ERR : vir.vc_tahead );
  289. #endif
  290.  
  291. #if    defined (DOS)
  292.  return(kbhit());
  293. #endif
  294.  
  295. #ifdef    OS2
  296. # ifdef EMXVIDEO
  297.     if (_cursvar.tahead == -1)    /* Nothing typed yet */
  298.     {                            /* See if there's anything */
  299.         _cursvar.tahead = _read_kbd (0, 0, 0);
  300.         if (_cursvar.tahead == 0)    /* Read additional */
  301.             _cursvar.tahead = (_read_kbd (0, 1, 0) << 8);
  302.     }
  303.     return(_cursvar.tahead != -1) ? 1 : 0;
  304. # else
  305. #  if !defined(MSC)
  306. /*    KbdCharIn(&keyInfo, IO_NOWAIT, 0);*/    /* get a character    */
  307.     KbdPeek(&keyInfo, 0);    /* peek at keyboard    */
  308.     return (keyInfo.fbStatus != 0);
  309. #  else
  310.  return(kbhit());
  311. #  endif
  312. # endif
  313. #endif
  314.  
  315. #ifdef UNIX
  316.     return(PDC_kbhit());
  317. #endif
  318.  
  319. #if defined(XCURSES)
  320.     return(XCurses_kbhit());
  321. #endif
  322. }         
  323.  
  324. /*man-start*********************************************************************
  325.  
  326.   PDC_get_bios_key()    - Returns the next key available from the BIOS.
  327.  
  328.   PDCurses Description:
  329.      This is a private PDCurses routine.
  330.  
  331.      Returns the next key code struck at the keyboard. If the low 8
  332.      bits are 0, the upper bits contain the extended character
  333.      code. If bit 0-7 are non-zero, the upper bits = 0.
  334.  
  335.   PDCurses Return Value:
  336.      This function returns OK on success and ERR on error.
  337.  
  338.   PDCurses Errors:
  339.      No errors are defined for this function.
  340.  
  341.   Portability:
  342.      PDCurses    int PDC_get_bios_key( void );
  343.  
  344. **man-end**********************************************************************/
  345.  
  346. int    PDC_get_bios_key(void)
  347. {
  348. #ifdef    FLEXOS
  349. unsigned ch = 0;
  350. #endif
  351.  
  352. #if    defined (DOS)
  353.     int ascii=0,scan=0;
  354.     static unsigned char keyboard_function=0xFF;
  355. #endif
  356.  
  357. #if    defined (OS2)
  358.     int ascii=0,scan=0;
  359. # ifndef EMXVIDEO
  360.     KBDKEYINFO keyInfo={0};
  361. # endif
  362. #endif
  363.  
  364. #ifdef PDCDEBUG
  365.     if (trace_on) PDC_debug("PDC_get_bios_key() - called\n");
  366. #endif
  367.  
  368. #ifdef    FLEXOS
  369.     retcode = s_read(0x00, 0L, (char *) &ch, 2L, 0L);
  370.     return( (retcode < 0L) ? ERR : ch );
  371. #endif
  372.  
  373. #if    defined (DOS)
  374.     if (keyboard_function == 0xFF)
  375.         {
  376.         regs.h.ah = 0x02;             /* get shift status for all keyboards */
  377.         int86(0x16, ®s, ®s);
  378.         scan = regs.h.al;
  379.         regs.h.ah = 0x12;             /* get shift status for enhanced keyboards */
  380.         int86(0x16, ®s, ®s);
  381.         if (scan == regs.h.al
  382.         &&  getdosmembyte(0x496) == 0x10)
  383.             keyboard_function = 0x10;
  384.         else
  385.             keyboard_function = 0x0;
  386.         }
  387.     regs.h.ah = keyboard_function;
  388.     int86(0x16, ®s, ®s);
  389.     ascii = regs.h.al;
  390.     scan = regs.h.ah;
  391. #endif
  392.  
  393. #ifdef    OS2
  394. # ifdef EMXVIDEO
  395.     if (_cursvar.tahead == -1)
  396.     {
  397.         _cursvar.tahead = _read_kbd (0, 1, 0);
  398.         if (_cursvar.tahead == 0)    /* Read additional */
  399.             _cursvar.tahead = (_read_kbd (0, 1, 0) << 8);
  400.     }
  401.     ascii = _cursvar.tahead & 0xff;
  402.     scan  = _cursvar.tahead >> 8;
  403.     _cursvar.tahead = -1;
  404. # else
  405.     KbdCharIn(&keyInfo, IO_WAIT, 0);    /* get a character    */
  406.     ascii = keyInfo.chChar;
  407.     scan = keyInfo.chScan;
  408. # endif
  409. #endif
  410.  
  411. #if    defined (DOS) || defined (OS2)
  412.     if (scan == 0x1c && ascii == 0x0a)  /* ^Enter */
  413.         return ((int) (0xfc00));
  414.     if ((scan == 0x03 && ascii == 0x00)  /* ^@ - Null */
  415.     ||  (scan == 0xe0 && ascii == 0x0d)  /* PadEnter */
  416.     ||  (scan == 0xe0 && ascii == 0x0a)) /* ^PadEnter */
  417.         return ((int) (ascii << 8));
  418.     if ((scan == 0x37 && ascii == 0x2a)  /* Star */
  419.     ||  (scan == 0x4a && ascii == 0x2d)  /* Minus */
  420.     ||  (scan == 0x4e && ascii == 0x2b)  /* Plus */
  421.     ||  (scan == 0xe0 && ascii == 0x2f)) /* Slash */
  422.         return ((int) ((ascii & 0x0f) | 0xf0) << 8);
  423.     if (ascii == 0x00 || ascii == 0xe0)
  424.         return ((int) (scan << 8));
  425.     return ((int) (ascii));
  426. #endif
  427. }
  428.  
  429. /*man-start*********************************************************************
  430.  
  431.   PDC_get_ctrl_break()    - return OS control break state
  432.  
  433.   PDCurses Description:
  434.      This is a private PDCurses routine.
  435.  
  436.      Returns the current OS Control Break Check state.
  437.  
  438.   PDCurses Return Value:
  439.      DOS:
  440.          This function returns TRUE on if the Control Break
  441.          Check is enabled otherwise FALSE is returned.
  442.  
  443.      FLEXOS:
  444.          This function returns TRUE on if the Keyboard Mode
  445.          allows a break to bre reported otherwise FALSE is returned.
  446.  
  447.   PDCurses Errors:
  448.      No errors are defined for this function.
  449.  
  450.   Portability:
  451.      PDCurses    bool    PDC_get_ctrl_break( void );
  452.  
  453. **man-end**********************************************************************/
  454.  
  455. bool    PDC_get_ctrl_break(void)
  456. {
  457. #ifdef    OS2
  458. #  if defined(CURSES__32BIT__) || defined(CSET2) || defined(TC)
  459. #     if defined(TC)
  460.     void __cdecl (*oldAction) (int);
  461. #     else
  462.     void (*oldAction) (int);
  463. #     endif
  464. #  endif
  465. #endif
  466.  
  467. #ifdef PDCDEBUG
  468.     if (trace_on) PDC_debug("PDC_get_ctrl_break() - called\n");
  469. #endif
  470.  
  471. #ifdef    FLEXOS
  472.     return ((kbmode & 0x01) ? TRUE : FALSE);
  473. #endif
  474.  
  475. #ifdef    DOS
  476.     regs.h.ah = 0x33;
  477.     regs.h.al = 0x00;
  478.     int86(0x21, ®s, ®s);
  479.     return ((bool) regs.h.dl);
  480. #endif
  481.  
  482. #ifdef    OS2
  483. #  if defined(CURSES__32BIT__) || defined(CSET2) || defined(TC)
  484.     oldAction = signal (SIGINT, SIG_DFL);
  485.     if (oldAction == SIG_ERR) return FALSE;
  486.     else signal (SIGINT, oldAction);
  487.     return (oldAction != SIG_IGN);
  488. #  else
  489.     PFNSIGHANDLER oldHandler, oldHandler1;
  490.     USHORT oldAction, oldAction1;
  491.     /* get the current state, and set to ignore */
  492.     DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction,
  493.         SIGA_IGNORE, SIG_CTRLBREAK);
  494.     /* restore the previous state */
  495.     DosSetSigHandler(oldHandler, &oldHandler1, &oldAction1,
  496.         oldAction, SIG_CTRLBREAK);
  497.     return(oldAction != SIGA_IGNORE);
  498. #  endif
  499. #endif
  500.  
  501. #ifdef UNIX
  502. /* INCOMPLETE - use signals?*/
  503. #endif
  504. }
  505.  
  506. /*man-start*********************************************************************
  507.  
  508.   PDC_rawgetch()    - Returns the next uninterpreted character (if available).
  509.  
  510.   PDCurses Description:
  511.      Gets a character without any interpretation at all and returns
  512.      it. If keypad mode is active for the designated window,
  513.      function key translation will be performed.  Otherwise,
  514.      function keys are ignored.  If nodelay mode is active in the
  515.      window, then PDC_rawgetch() returns -1 if no character is
  516.      available.
  517.  
  518.      WARNING:  It is unknown whether the FUNCTION key translation
  519.            is performed at this level. --Frotz 911130 BUG
  520.  
  521.   PDCurses Return Value:
  522.      This function returns OK on success and ERR on error.
  523.  
  524.   PDCurses Errors:
  525.      No errors are defined for this function.
  526.  
  527.   Portability:
  528.      PDCurses    int    PDC_rawgetch( void );
  529.  
  530. **man-end**********************************************************************/
  531.  
  532. int    PDC_rawgetch(void)
  533. {
  534. extern    WINDOW*    _getch_win_;
  535. /* extern    WINDOW*    w;*/   /* w defined in wgetch() as static - _getch_win_ */
  536.                         /* is the same window - all references to w changed*/
  537.                         /* to _getch_win_ - marked with @@ */
  538.  
  539.     int    c=0;
  540.     int    oldc=0;
  541.  
  542. #ifdef PDCDEBUG
  543.     if (trace_on) PDC_debug("PDC_rawgetch() - called\n");
  544. #endif
  545.  
  546.     if (_getch_win_ == (WINDOW *)NULL)   /* @@ */
  547.         return( -1 );
  548.  
  549.     if (_getch_win_->_nodelay && !PDC_breakout()) /* @@ */
  550.         return( -1 );
  551.  
  552. #ifdef UNIX
  553.     c = getchar();
  554.     return(c);
  555. #endif
  556.  
  557. #if defined(XCURSES)
  558.     c = XCurses_rawgetch();
  559.     return(c);
  560. #endif
  561.  
  562.     while (1)        /* loop to get valid char */
  563.     {
  564.         c = PDC_get_bios_key();
  565.         oldc = c;
  566.         /*
  567.          * Return the key if it is not a special key.
  568.          */
  569.         if ((c = PDC_validchar(c)) >= 0)
  570.         {        /* get & check next char */
  571.             return( c );
  572.         }
  573.         if (_getch_win_->_use_keypad)
  574.             return( oldc );
  575.     }
  576. }
  577.  
  578. /*man-start*********************************************************************
  579.  
  580.   PDC_set_ctrl_break()    - Enables/Disables the host OS BREAK key check.
  581.  
  582.   PDCurses Description:
  583.      This is a private PDCurses routine.
  584.  
  585.      Enables/Disables the host OS BREAK key check. This function toggles
  586.      the BREAK setting. If it was on, it turns itoff; if it was aff it turns
  587.      it on.
  588.  
  589.   PDCurses Return Value:
  590.      This function returns OK on success and ERR on error.
  591.  
  592.   PDCurses Errors:
  593.      No errors are defined for this function.
  594.  
  595.   Portability:
  596.      PDCurses    int PDC_set_ctrl_break( bool setting );
  597.  
  598. **man-end**********************************************************************/
  599.  
  600. int    PDC_set_ctrl_break(bool setting)
  601. {
  602. #ifdef PDCDEBUG
  603.     if (trace_on) PDC_debug("PDC_set_ctrl_break() - called\n");
  604. #endif
  605.  
  606. #ifdef    FLEXOS
  607.     retcode = s_get(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  608.     if (retcode < 0L)
  609.         return( ERR );
  610.  
  611.     vir.vc_kbmode = ((vir.vc_kbmode & ~0x01) & (setting) ? 0x01 : 0x00);
  612.  
  613.     retcode = s_set(T_VIRCON, 0L, (char *) &vir, (long) sizeof(vir));
  614.     return( (retcode < 0L) ? ERR : OK );
  615. #endif
  616.  
  617. #ifdef    DOS
  618. #  ifdef    NDP
  619.     if( setting )
  620.         _ignore_breaks();
  621.     else
  622.         _watch_breaks();
  623. #  else
  624.     regs.h.ah = 0x33;
  625.     regs.h.al = 0x00;
  626.     regs.h.dl = (unsigned char) (setting ? 1 : 0);
  627.     int86(0x21, ®s, ®s);
  628. #  endif
  629.     return( OK );
  630. #endif
  631.  
  632. #ifdef    OS2
  633. #  if defined (CURSES__32BIT__) || defined (CSET2) || defined(TC)
  634.     if (setting) {
  635.         signal (SIGINT, SIG_DFL);
  636.         signal (SIGBREAK, SIG_DFL);
  637.     } else {
  638.         signal (SIGINT, SIG_IGN);
  639.         signal (SIGBREAK, SIG_IGN);
  640.         }
  641.     return( OK );
  642. #  else
  643.     PFNSIGHANDLER oldHandler;
  644.     USHORT oldAction, Action;
  645.  
  646.     /* turn off control C checking */
  647.     if (setting)
  648.         Action = SIGA_KILL;
  649.     else
  650.         Action = SIGA_IGNORE;
  651.     DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction,
  652.         Action, SIG_CTRLBREAK);
  653.     DosSetSigHandler((PFNSIGHANDLER) NULL, &oldHandler, &oldAction,
  654.         Action, SIG_CTRLC);
  655.     return( OK );
  656. #  endif    
  657. #endif
  658.  
  659. #ifdef UNIX
  660. /* INCOMPLETE */
  661. #endif
  662. }
  663.  
  664. /*man-start*********************************************************************
  665.  
  666.   PDC_sysgetch()    - Return a character using default system routines.
  667.  
  668.   PDCurses Description:
  669.      This is a private PDCurses function.
  670.  
  671.      Gets a character without normal ^S, ^Q, ^P and ^C interpretation
  672.      and returns it.  If keypad mode is active for the designated
  673.      window, function key translation will be performed. Otherwise,
  674.      function keys are ignored. If nodelay mode is active in the
  675.      window, then sysgetch() returns -1 if no character is
  676.      available.
  677.  
  678.   PDCurses Return Value:
  679.      This function returns OK upon success otherwise ERR is returned.
  680.  
  681.   PDCurses Errors:
  682.      No errors are defined for this routine.
  683.  
  684.   Portability:
  685.      PDCurses    int    PDC_sysgetch( void );
  686.  
  687. **man-end**********************************************************************/
  688.  
  689. #ifdef UNIX
  690. static bool alarmed;
  691. #endif
  692.  
  693. int    PDC_sysgetch(void)
  694. {
  695. extern    WINDOW*    _getch_win_;
  696. /* extern    WINDOW*    w;*/   /* w defined in wgetch() as static - _getch_win_ */
  697.                         /* is the same window - all references to w changed*/
  698.                         /* to _getch_win_ - marked with @@ */
  699.  
  700.     int c=0;
  701.  
  702. #ifdef UNIX
  703.     void (*oldsig)();
  704.     void sigalrm();
  705.     char keybuf[10];
  706.     char *bufp=keybuf;
  707.     int val=0;
  708.     register int i=0;
  709. #define MATCH_FALSE 0
  710. #define MATCH_PARTIAL 1
  711. #define MATCH_TRUE 2
  712.     char match=0;
  713. #endif
  714.  
  715. #ifdef PDCDEBUG
  716.     if (trace_on) PDC_debug("PDC_sysgetch() - called\n");
  717. #endif
  718.  
  719.     if (_getch_win_ == (WINDOW *)NULL)  /* @@ */
  720.         return (-1);
  721.  
  722.     if (_getch_win_->_nodelay && !PDC_breakout())
  723.         return (-1);
  724.  
  725. #ifdef UNIX
  726. /* INCOMPLETE */
  727.     oldsig = signal(SIGALRM,sigalrm);
  728.     alarmed = FALSE;
  729.     while(1)
  730.         {
  731.         c = getchar();
  732.         if (c != EOF)
  733.             {
  734.             *(bufp+i++) = c;
  735.             *(bufp+i) = '\0';
  736.             }
  737.         if (alarmed)
  738.             break;
  739.         val = find_key(keybuf,i);
  740.         if (val == MATCH_FALSE)
  741.             {
  742.             alarm(0);
  743.             signal(SIGALRM,oldsig);
  744.             return(keybuf[0]);
  745.             }
  746.         if (val != MATCH_PARTIAL)
  747.             {
  748.             alarm(0);
  749.             signal(SIGALRM,oldsig);
  750.             return(val);
  751.             }
  752.         alarm(1);
  753.         }
  754.     alarm(0);
  755.     signal(SIGALRM,oldsig);
  756. /* INCOMPLETE */
  757.     return(c);
  758. #else
  759.     while (1)
  760.     {
  761.         c = PDC_get_bios_key();
  762. #if    defined (DOS) || defined (OS2)
  763.         /*
  764.          * Return the key if it is not a special key.
  765.          */
  766.         if ((unsigned int)c < 256)
  767.             return(c);
  768. #endif
  769.         if ((c = PDC_validchar(c)) >= 0)
  770.         {
  771.             return (c);        /* get & check next char */
  772.         }
  773.     }
  774. #endif
  775. }
  776.  
  777. #ifdef UNIX
  778. static void sigalrm()
  779. {
  780.     alarmed = TRUE;
  781.     signal(SIGALRM,sigalrm);
  782. }
  783. static int find_key(char *seq,int len)
  784. {
  785.     register int i=0;
  786.  
  787.     for (i=0;i<_cursvar.number_keys;i++)
  788.         {
  789.         if (strcmp(seq,_cursvar.key_seq[i]) == 0)
  790.             return(_cursvar.key_num[i]);
  791.         if (memcmp(seq,_cursvar.key_seq[i],len) == 0)
  792.             return(MATCH_PARTIAL);
  793.         }
  794.     return(MATCH_FALSE);
  795. }
  796. #endif
  797.  
  798. /*man-start*********************************************************************
  799.  
  800.   PDC_validchar()    - validate/translate passed character
  801.   
  802.   PDCurses Description:
  803.       This is a private PDCurses function.
  804.   
  805.       Checks that 'c' is a valid character, and if so returns it,
  806.       with function key translation applied if 'w' has keypad mode
  807.       set.  If char is invalid, returns -1.
  808.   
  809.   PDCurses Return Value:
  810.       This function returns -1 if the passed character is invalid, or
  811.       the WINDOW* 'w' is NULL, or 'w's keypad is not active.
  812.   
  813.       This function returns 0 under Flexos if the passed character
  814.       is 0x0300.  (-:Forget why.  --Frotz    911130:-)
  815.   
  816.       Otherwise, this function returns the PDCurses equivalent of the
  817.       passed character.  See the function key and key macros in
  818.       <curses.h>
  819.   
  820.   PDCurses Errors:
  821.       There are no errors defined for this routine.
  822.   
  823.   Portability:
  824.       PDCurses    int    PDC_validchar( int c );
  825.  
  826. **man-end**********************************************************************/
  827.  
  828. int    PDC_validchar(int c)
  829. {
  830. extern    WINDOW*    _getch_win_;
  831. /* extern    WINDOW*    w;*/   /* w defined in wgetch() as static - _getch_win_ */
  832.                         /* is the same window - all references to w changed*/
  833.                         /* to _getch_win_ - marked with @@ */
  834.  
  835.     int *scanp=NULL;
  836.  
  837. #ifdef PDCDEBUG
  838.     if (trace_on) PDC_debug("PDC_validchar() - called\n");
  839. #endif
  840.  
  841.     if (_getch_win_ == (WINDOW *)NULL)
  842.         return (-1);    /* bad window pointer      */
  843.  
  844. #ifdef    FLEXOS
  845.     if (c == 0x0300)
  846.         return (0);    /* special case, ^@ = NULL      */
  847. #endif
  848.     if ((unsigned int)c < 256)    return (c);  /* normal character */
  849.     if (!(_getch_win_->_use_keypad))    return (-1); /* skip if keys if !keypad mode */
  850.  
  851. #if    defined (DOS) || defined (OS2)
  852.     /*
  853.     * Under DOS, extended keys are in the upper byte.  Shift down for a
  854.     * comparison.
  855.     */
  856.     c = (c >> 8) & 0xFF;
  857. #endif
  858.  
  859. #if defined(XCURSES)
  860. /* INCOMPLETE */
  861. #else
  862.     scanp = kptab;
  863.     while (*scanp > 0)    /* search for value         */
  864.     {            /* (stops on table entry 0x100) */
  865.         if (*scanp++ == c)
  866.         {
  867.             return (*scanp);    /* found, return it */
  868.         }
  869.         scanp++;
  870.     }
  871.     return( -1 );        /* not found, invalid */
  872. #endif
  873. }
  874.